home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdev8510.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.0 KB  |  145 lines

  1. /* Copyright (C) 1990, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdev8510.c,v 1.2 2000/09/19 19:00:11 lpd Exp $*/
  20. /*
  21.  * C.Itoh M8510 printer driver for ghostscript.
  22.  *
  23.  * By Bob Smith <bob@snuffy.penfield.ny.us>
  24.  */
  25.  
  26. #include "gdevprn.h"
  27.  
  28. /* The device descriptor */
  29. private dev_proc_print_page(m8510_print_page);
  30. gx_device_printer far_data gs_m8510_device =
  31.     prn_device(prn_std_procs, "m8510",
  32.         85,                /* width_10ths, 8.5" */
  33.         110,                /* height_10ths, 11" */
  34.         160,                /* x_dpi */
  35.         144,                /* y_dpi */
  36.         0,0,0.5,0,            /* left, bottom, right, and top margins */
  37.         1, m8510_print_page);
  38.  
  39. /* ------ forward declarations ------ */
  40.  
  41. private void m8510_output_run(P4(gx_device_printer *pdev,
  42.     byte *out, int pass, FILE *prn_stream));
  43.  
  44. /* ------ internal routines ------ */
  45.  
  46. /* Send the page to the printer. */
  47. private int
  48. m8510_print_page(gx_device_printer *pdev, FILE *prn_stream)
  49. {
  50.     int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  51.     byte *in1 = (byte *) gs_malloc(8, line_size, "m8510_print_page(in1)");
  52.     byte *in2 = (byte *) gs_malloc(8, line_size, "m8510_print_page(in2)");
  53.     byte *out = (byte *) gs_malloc(8, line_size, "m8510_print_page(out)");
  54.     int lnum = 0;
  55.     int code = 0;
  56.     byte *inp, *in_end, *outp;
  57.     int i;
  58.  
  59.     if (in1 == 0 || in2 == 0 || out == 0) {
  60.         code = gs_error_VMerror;
  61.         gs_note_error(code);
  62.         goto out;
  63.     }
  64.  
  65.     /*
  66.      * Initialize the printer.
  67.      * NLQ mode, proportional print (160x144 dpi).
  68.      * and 16/144" linefeeds.
  69.      */
  70.     fwrite("\033m2\033P\033T16", 1, 9, prn_stream);
  71.  
  72.     /* Transfer pixels to printer */
  73.     while ( lnum < pdev->height ) {
  74.         /* get a raster */
  75.         for (i = 7; i >= 0; i--) {
  76.             gdev_prn_copy_scan_lines(pdev, lnum, &in1[i*line_size], line_size);
  77.             lnum++;
  78.             gdev_prn_copy_scan_lines(pdev, lnum, &in2[i*line_size], line_size);
  79.             lnum++;
  80.         }
  81.  
  82.         /* Transpose the 1st pass of data. */
  83.         in_end = in1 + line_size;
  84.         for (inp = in1, outp = out; inp < in_end; inp++, outp += 8)
  85.             gdev_prn_transpose_8x8(inp, line_size, outp, 1);
  86.  
  87.         /* send the 1st line */
  88.         m8510_output_run(pdev, out, 0, prn_stream);
  89.  
  90.         /* Transpose the 2nd pass of data. */
  91.         in_end = in2 + line_size;
  92.         for (inp = in2, outp = out; inp < in_end; inp++, outp += 8)
  93.             gdev_prn_transpose_8x8(inp, line_size, outp, 1);
  94.  
  95.         /* send the 2nd line */
  96.         m8510_output_run(pdev, out, 1, prn_stream);
  97.     }
  98.  
  99.     /* reset the printer. */
  100.     fwrite("\033c1", 1, 3, prn_stream);
  101.     fflush(prn_stream);
  102.  
  103. out:;
  104.     if (out) gs_free((char *) out, 8, line_size, "m8510_print_page(out)");
  105.     if (in2) gs_free((char *) in2, 8, line_size, "m8510_print_page(in2)");
  106.     if (in1) gs_free((char *) in1, 8, line_size, "m8510_print_page(in1)");
  107.  
  108.     return code;
  109. }
  110.  
  111. private void
  112. m8510_output_run(gx_device_printer *pdev,
  113.     byte *out, int pass, FILE *prn_stream)
  114. {
  115.     byte *out_end = out + pdev->width;
  116.     char tmp[10];
  117.     int count;
  118.  
  119.     /*
  120.      * Remove trailing 0s.
  121.      * out must be a multiple of 8 bytes.
  122.      */
  123.     while (out_end > out
  124.         && out_end[-1] == 0
  125.         && out_end[-2] == 0
  126.         && out_end[-3] == 0
  127.         && out_end[-4] == 0
  128.         && out_end[-5] == 0
  129.         && out_end[-6] == 0
  130.         && out_end[-7] == 0
  131.         && out_end[-8] == 0)
  132.             out_end -= 8;
  133.  
  134.     /* Transfer the line of data. */
  135.     count = out_end - out;
  136.     if (count) {
  137.         sprintf(tmp, "\033g%03d", count/8);
  138.         fwrite(tmp, 1, 5, prn_stream);
  139.         fwrite(out, 1, count, prn_stream);
  140.         fwrite("\r", 1, 1, prn_stream);
  141.     }
  142.  
  143.     if (pass) fwrite("\n", 1, 1, prn_stream);
  144. }
  145.